home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / dejagnu.lha / dejagnu-1.0.1 / tcl / doc / Interp.3 < prev    next >
Text File  |  1993-02-14  |  6KB  |  126 lines

  1. '\"
  2. '\" Copyright 1989 Regents of the University of California
  3. '\" Permission to use, copy, modify, and distribute this
  4. '\" documentation for any purpose and without fee is hereby
  5. '\" granted, provided that this notice appears in all copies.
  6. '\" The University of California makes no representations about
  7. '\" the suitability of this material for any purpose.  It is
  8. '\" provided "as is" without express or implied warranty.
  9. '\" 
  10. .so man.macros
  11. .HS Tcl_Interp tcl
  12. .BS
  13. .SH NAME
  14. Tcl_Interp \- client-visible fields of interpreter structures
  15. .SH SYNOPSIS
  16. .nf
  17. \fB#include <tcl.h>\fR
  18. .sp
  19. typedef struct {
  20.     char *\fIresult\fR;
  21. .VS
  22.     Tcl_FreeProc *\fIfreeProc\fR;
  23. .VE
  24.     int \fIerrorLine\fR;
  25. } Tcl_Interp;
  26.  
  27. .VS
  28. typedef void Tcl_FreeProc(char *\fIblockPtr\fR);
  29. .VE
  30. .BE
  31.  
  32. .SH DESCRIPTION
  33. .PP
  34. The \fBTcl_CreateInterp\fR procedure returns a pointer to a Tcl_Interp
  35. structure.  This pointer is then passed into other Tcl procedures
  36. to process commands in the interpreter and perform other operations
  37. on the interpreter.  Interpreter structures contain many many fields
  38. that are used by Tcl, but only three that may be accessed by
  39. .VS
  40. clients:  \fIresult\fR, \fIfreeProc\fR, and \fIerrorLine\fR.
  41. .PP
  42. The \fIresult\fR and \fIfreeProc\fR fields are used to return
  43. results or error messages from commands.
  44. This information is returned by command procedures back to \fBTcl_Eval\fR,
  45. and by \fBTcl_Eval\fR back to its callers.
  46. The \fIresult\fR field points to the string that represents the
  47. result or error message, and the \fIfreeProc\fR field tells how
  48. to dispose of the storage for the string when it isn't needed anymore.
  49. The easiest way for command procedures to manipulate these
  50. fields is to call procedures like \fBTcl_SetResult\fR
  51. or \fBTcl_AppendResult\fR;  they
  52. will hide all the details of managing the fields.
  53. The description below is for those procedures that manipulate the
  54. fields directly.
  55. .PP
  56. Whenever a command procedure returns, it must ensure
  57. that the \fIresult\fR field of its interpreter points to the string
  58. being returned by the command.
  59. The \fIresult\fR field must always point to a valid string.
  60. If a command wishes to return no result then \fIinterp->result\fR
  61. should point to an empty string.
  62. Normally, results are assumed to be statically allocated,
  63. which means that the contents will not change before the next time
  64. \fBTcl_Eval\fR is called or some other command procedure is invoked.
  65. In this case, the \fIfreeProc\fR field must be zero.
  66. Alternatively, a command procedure may dynamically
  67. allocate its return value (e.g. using \fBmalloc\fR)
  68. and store a pointer to it in \fIinterp->result\fR.
  69. In this case, the command procedure must also set \fIinterp->freeProc\fR
  70. to the address of a procedure that can free the value (usually \fBfree\fR).
  71. If \fIinterp->freeProc\fR is non-zero, then Tcl will call \fIfreeProc\fR
  72. to free the space pointed to by \fIinterp->result\fR before it
  73. invokes the next command.
  74. If a client procedure overwrites \fIinterp->result\fR when
  75. \fIinterp->freeProc\fR is non-zero, then it is responsible for calling
  76. \fIfreeProc\fR to free the old \fIinterp->result\fR (the \fBTcl_FreeResult\fR
  77. macro should be used for this purpose).
  78. .PP
  79. \fIFreeProc\fR should have arguments and result that match the
  80. \fBTcl_FreeProc\fR declaration above:  it receives a single
  81. argument which is a pointer to the result value to free.
  82. In most applications \fBfree\fR is the only non-zero value ever
  83. used for \fIfreeProc\fR.
  84. However, an application may store a different procedure address
  85. in \fIfreeProc\fR in order to use an alternate memory allocator
  86. or in order to do other cleanup when the result memory is freed.
  87. .PP
  88. As part of processing each command, \fBTcl_Eval\fR initializes
  89. \fIinterp->result\fR
  90. and \fIinterp->freeProc\fR just before calling the command procedure for
  91. the command.  The \fIfreeProc\fR field will be initialized to zero,
  92. and \fIinterp->result\fR will point to an empty string.  Commands that
  93. do not return any value can simply leave the fields alone.
  94. .VE
  95. Furthermore, the empty string pointed to by \fIresult\fR is actually
  96. part of an array of \fBTCL_RESULT_SIZE\fR characters (approximately 200).
  97. If a command wishes to return a short string, it can simply copy
  98. it to the area pointed to by \fIinterp->result\fR.  Or, it can use
  99. the sprintf procedure to generate a short result string at the location
  100. pointed to by \fIinterp->result\fR.
  101. .PP
  102. It is a general convention in Tcl-based applications that the result
  103. of an interpreter is normally in the initialized state described
  104. in the previous paragraph.
  105. Procedures that manipulate an interpreter's result (e.g. by
  106. returning an error) will generally assume that the result
  107. has been initialized when the procedure is called.
  108. If such a procedure is to be called after the result has been
  109. changed, then \fBTcl_ResetResult\fR should be called first to
  110. reset the result to its initialized state.
  111. .PP
  112. The \fIerrorLine\fR
  113. field is valid only after \fBTcl_Eval\fR returns
  114. a \fBTCL_ERROR\fR return code.  In this situation the \fIerrorLine\fR
  115. field identifies the line number of the command being executed when
  116. the error occurred.  The line numbers are relative to the command
  117. being executed:  1 means the first line of the command passed to
  118. \fBTcl_Eval\fR, 2 means the second line, and so on.
  119. The \fIerrorLine\fR field is typically used in conjunction with
  120. \fBTcl_AddErrorInfo\fR to report information about where an error
  121. occurred.
  122. \fIErrorLine\fR should not normally be modified except by \fBTcl_Eval\fR.
  123.  
  124. .SH KEYWORDS
  125. free, initialized, interpreter, malloc, result
  126.